<template>
  <div class="login">
    <Header title="新用户注册"></Header>
    <section>
      <div class="login-tel">
        <input type="text" v-model="userTel" placeholder="输入手机号" pattern="[0-9]*" />
      </div>
      <div class="login-tel">
        <input type="password" v-model="userPwd" placeholder="输入密码" pattern="\w{6,12}" />
      </div>
      <div class="login-btn" @click="goRegister">注册</div>
    </section>
  </div>
</template>

<script setup>
import Header from '@/components/My/Header.vue'
import { ref, defineComponent, onMounted, onBeforeUnmount } from 'vue'
import { showToast } from 'vant'
import userService from '@/common/service/user.service.js'
import { useAppStore } from '@/stores'

const sStore = useAppStore()
onMounted(() => {
  sStore.setTabbarStatus(false)
})
onBeforeUnmount(() => {
  sStore.setTabbarStatus(true)
})
const registerVC = defineComponent({
  name: 'Register',
})
const userTel = ref('13510129004')
const userPwd = ref('123456')
const goRegister = () => {
  //验证
  if (!userService.validateUserTel(userTel.value)) return
  if (!userService.validateUserPwd(userPwd.value)) return
  const data = {
    userAccount: userTel.value,
    userPassword: userPwd.value,
  }
  userService.register(data).then((result) => {
    showToast(result?.message)
    console.log('注册的信息', result)
  })
}
</script>

<style scoped>
.login {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #f1f1f1;
}

.login-tel {
  margin: 0.266666rem 0;
  width: 8.933333rem;
  height: 1.173333rem;
}

.login-tel input {
  box-sizing: border-box;
  padding: 0 0.266666rem;
  line-height: 1.173333rem;
  background-color: #ffffff;
  border: 1px solid #ccc;
  border-radius: 6px;
  width: 100%;
}

.login-btn {
  margin: 0.266666rem 0;
  width: 8.933333rem;
  height: 1.173333rem;
  line-height: 44px;
  color: #fff;
  text-align: center;
  background-color: #ff5777;
  border-radius: 6px;
}
</style>
